/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package snippet.lab4;

import java.io.*;

/**
 *
 * @author hoang.pt
 */
public class FileInputStreamDemo {

    public static void main(String[] args) {
        System.out.println("Test file input stream demo");
        
        FileInputStream fileStream = null;
        try {
            fileStream = new FileInputStream("test.txt");

            //set flag
            boolean eofFlag = false;

            //---read until end file
            while (!eofFlag) {
                //read file
                int intVal = fileStream.read();

                //print in monitor
                System.out.print(intVal +" ");
                if (intVal == -1) {
                    eofFlag = true;
                }
            }
            
        } catch (FileNotFoundException ex) {

        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            try {
                fileStream.close();
            } catch (IOException ex) {

            }
        }
    }

}
